using CompilerGenerated;
using System;
using UnityEngine;
using UnityScript.Lang;

[Serializable]
public class Visualizer : MonoBehaviour
{
	public float[] freqData;

	public AudioListener listener;

	public float[] band;

	public GameObject[] g;

	public float offset;

	public float y;

	public float z;

	public Transform pt;

	public ParticleSystem ParticleSys;

	public int multiplier;

	private __Visualizer_0024callable0_002481_32__ sqrt;

	public Visualizer()
	{
		freqData = new float[8192];
		offset = -2f;
		multiplier = 17;
		sqrt = Mathf.Sqrt;
	}

	public void Start()
	{
		pt = ParticleSys.transform;
		int num = Extensions.get_length((System.Array)freqData);
		int num2 = 0;
		for (int i = 0; i < Extensions.get_length((System.Array)freqData); i++)
		{
			num /= 2;
			if (num == 0)
			{
				break;
			}
			num2++;
		}
		band = new float[num2 + 1];
		for (int j = 0; j < Extensions.get_length((System.Array)band); j++)
		{
			band[j] = 0f;
		}
		InvokeRepeating("check", 0f, 0.02f);
	}

	public void check()
	{
		AudioListener.GetSpectrumData(freqData, 0, FFTWindow.Rectangular);
		int num = 0;
		int num2 = 2;
		for (int i = default(int); i < Extensions.get_length((System.Array)freqData); i++)
		{
			float num3 = freqData[i];
			float num4 = band[num];
			band[num] = ((num3 <= num4) ? num4 : num3);
			if (i <= num2 - 3)
			{
				continue;
			}
			num++;
			num2 *= 2;
			if (!(band[1] <= 0.02f))
			{
				ParticleSystem.Particle[] array = new ParticleSystem.Particle[(int)((band[1] + band[2] + band[3] + band[4] + band[5]) * (float)multiplier)];
				int particles = ParticleSys.GetParticles(array);
				for (int j = 0; j < particles; j++)
				{
					array[j].color = new Color(band[4] * 3f, (band[3] + band[2]) * 3f, (band[1] + band[5] + band[4]) * 15f, band[1] + band[2] + band[3] + band[4] + band[5] * 1f);
					pt.position = new Vector3(band[3] * 50f, band[4] * 30f, (0f - (band[1] + band[2] + band[5] + band[4])) * 5f);
					array[j].velocity = new Vector3((0f - band[3]) * 25f, (0f - band[4]) * 30f, band[3] * 30f);
					ParticleSys.startSpeed = (band[1] + band[2] + band[3] + band[4] + band[4] + band[5]) * 40f;
				}
				ParticleSys.SetParticles(array, particles);
				band[num] = 0f;
			}
		}
	}

	public void Main()
	{
	}
}
